package com.example.testapplication

import android.app.Activity
import android.content.Context
import android.util.Log
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleEventObserver
import androidx.lifecycle.LifecycleOwner

class MyView(lifecycle : LifecycleOwner) : LifecycleEventObserver {

    init {
        lifecycle.lifecycle.addObserver(this)
    }

    override fun onStateChanged(source: LifecycleOwner, event: Lifecycle.Event) {
        Log.e("onStateChanged" ,"" + event.name)
    }

    fun logActivity(context: Context){
        val list = ((context as Activity).application as MyApp).myLifecycle.activities
        for (ii in 0 until list.size) {
            Log.e("已经打开的activity", "--->" + list[ii].toString())
        }
    }

}